import axios from 'axios';
// 创建axios实例
const service = axios.create({
  timeout: 60000,
  headers: {
    Pragma: 'no-cache'
  }
});

// 请求拦截
service.interceptors.request.use(config => config, (error) => {
  // 错误处理
  // eslint-disable-next-line
  console.log(error);
  Promise.reject(error);
});

// 返回拦截
service.interceptors.response.use(
  // response => response.data,
  (response) => {
    const { code, msg, errorMsg } = response.data || {};
    if ((code && code !== '0') || errorMsg) {
      return Promise.reject(new Error(msg));
    }
    return Promise.resolve(response.data);
  },
  (error) => {
    return Promise.reject(error);
  });

export default service;
